package pro.softzhang.algo.lc900;

import pro.softzhang.algo.flag.knowledge.KGraph;

/**
 *
 */
@KGraph
public class LC997_FindTheTownJudge {
    public static void main(String[] args) {

    }

    /**
     *
     */
    static
    class Solution {
        public int findJudge(int n, int[][] trust) {
            int[] inDegrees = new int[n + 1], outDegrees = new int[n + 1];
            for (int[] edge : trust) {
                int x = edge[0], y = edge[1];
                inDegrees[y]++;
                outDegrees[x]++;
            }

            for (int i = 1; i <= n; i++)
                if (inDegrees[i] == n - 1 && outDegrees[i] == 0)
                    return i;

            return -1;
        }
    }
}
